﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Administrator_ctKienThucVeMat : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.QueryString["ID"] == null)
        {
            this.FormView1.DefaultMode = FormViewMode.Insert;
        }
    }
    
    protected void FormView1_ItemInserted(object sender, FormViewInsertedEventArgs e)
    {
        FileUpload fu = (FileUpload)this.FormView1.FindControl("InsertAnh");
        if (fu.HasFile)
        {
            string type = fu.FileName.Substring(fu.FileName.Length - 3, 3);
            KienThucVeMatDA kda = new KienThucVeMatDA();
            string maxid = kda.getMaxID();
            string pat = Server.MapPath("~/Image/KienThucVeMat/" + maxid + "." + type);
            fu.SaveAs(pat);
            kda.updateImage(type);
            Response.Redirect("ctHuongDanThanToan.aspx?ID=" + maxid);
        }
        
    }
    protected void FormView1_ItemUpdated(object sender, FormViewUpdatedEventArgs e)
    {
        FileUpload fu = (FileUpload)this.FormView1.FindControl("UpdateAnh");
        if (fu.HasFile)
        {
            string type = fu.FileName.Substring(fu.FileName.Length - 3, 3);
            KienThucVeMatDA kda = new KienThucVeMatDA();
            string pat = Server.MapPath("~/Image/KienThucVeMat/" + Request.QueryString["ID"] + "." + type);
            fu.SaveAs(pat);
            kda.updateImage(type,Request.QueryString["ID"].ToString());
        }
    }
    protected void LinkButton2_Click(object sender, EventArgs e)
    {
        Response.Redirect("HuongDanThanhToan.aspx");
    }

    protected void InsertCancelButton_Click(object sender, EventArgs e)
    {
        Response.Redirect("HuongDanThanhToan.aspx");
    }
}